﻿using Microsoft.AspNetCore.Mvc;
using Ubiquity.Core.Extend;
using Ubiquity.Core.Web;

namespace Ubiquity.Web.Filters
{
    /// <summary>
    /// 基类
    /// </summary>
   // [Authorize]
    // [HandlerError]
    public abstract class BaseController : Controller
    {

       // protected static IDbContextConfig ContextConfig = new DbContextConfig("Server=.;Initial Catalog=JewelleryManage;User ID=sa;Password=123456;");
         //   FactoryProvider.CreateDbContext("Server=.;Initial Catalog=JewelleryManage;User ID=sa;Password=123456;");
        ///// <summary>
        ///// 日志文件
        ///// </summary>
        //public ILog Log
        //{
        //    get { return new Log(); }
        //}
        [HttpGet]
        [Authorize]
        public virtual ActionResult Index()
        {
            return View();
        }
        [HttpGet]
        [Authorize]
        public virtual ActionResult Form()
        {
            return View();
        }
        [HttpGet]
        [Authorize]
        public virtual ActionResult Details()
        {
            return View();
        }
        /// <summary>
        /// 成功返回
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        protected virtual ActionResult Success(string message)
        {
            return Content(new AjaxResult { state = ResultType.success.ToString(), message = message }.ToJson());
        }
        /// <summary>
        /// 成功返回
        /// </summary>
        /// <param name="message"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        protected virtual ActionResult Success(string message, object data)
        {
            return Content(new AjaxResult { state = ResultType.success.ToString(), message = message, data = data }.ToJson());
        }
        /// <summary>
        /// 错误返回
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        protected virtual ActionResult Error(string message)
        {
            return Content(new AjaxResult { state = ResultType.error.ToString(), message = message }.ToJson());
        }
    }
}
